<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>不迷失-Admin 书籍目录管理</title>
    <div th:replace="head"></div>
</head>

<body class="hold-transition skin-blue sidebar-mini ">
<div class="wrapper">

    <div th:replace="header"></div>
    <div th:replace="sidebar"></div>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">

        <!-- Main content -->
        <section class="content">

            <div class="row">
                <div class="col-md-12">
                    <!-- Horizontal Form -->
                    <div class="box box-info">
                        <div class="box-header with-border">
                            <h3 class="box-title">书籍目录管理</h3>
                        </div>
                        <!-- /.box-header -->

                        <h2 th:if="${rep!=null &amp;&amp;!rep.success}" th:text="${rep.msg}"></h2>

                        <!-- form start -->
                        <form th:if="${rep==null || rep.success}" class="form-horizontal" th:action="@{${api}}"
                              method="post">
                            <div class="box-body">
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-2 control-label">id</label>

                                    <div class="col-sm-10">
                                        <input type="text" name="id" th:value="${rep}?(${rep.data}? ${rep.data.id})"
                                               class="form-control" id="inputEmail3"
                                               placeholder="" th:readonly="${rep}?(${rep.data}?true)"
                                               required="required" maxlength="50"/>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-2 control-label">label</label>

                                    <div class="col-sm-10">
                                        <input type="text" name="label"
                                               th:value="${rep}?(${rep.data}? ${rep.data.label})"
                                               class="form-control" id="inputEmail3" placeholder=""
                                               required="required" maxlength="30"/>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-2 control-label">链接(如果是链接到某篇博客请输入博客id,否则输入完整地址)</label>

                                    <div class="col-sm-10">
                                        <input type="text" required="required" name="url"
                                               th:value="${rep}?(${rep.data}?(${rep.data.url}? ${rep.data.url}))"
                                               class="form-control" id="url" placeholder=""
                                               maxlength="225"/>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-2 control-label">排序</label>

                                    <div class="col-sm-10">
                                        <input type="number" name="order"
                                               th:value="${rep}?(${rep.data}? ${rep.data.order}) : 10"
                                               class="form-control" id="inputEmail3" placeholder=""
                                        />
                                        <input type="hidden" name="bookId" th:value="${bookId}"/>
                                        <input type="hidden" name="path"
                                               th:value="${rep}?(${rep.data}? ${rep.data.path}) : (${parentPath} ? ${parentPath} :0)"/>
                                    </div>
                                </div>

                                <br/><br/>
                            </div>
                            <!-- /.box-body -->
                            <div class="box-footer" style="text-align: center;">
                                <button type="button" class="btn btn-info" onclick="backToList();">返回</button>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <button id="submitBtn" type="submit" class="btn btn-info">提交</button>
                            </div>
                            <!-- /.box-footer -->
                        </form>
                    </div>
                    <!-- /.box -->

                </div>
            </div>
            <!-- /.row -->

        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

    <div th:replace="footer"></div>
</div>
<!-- ./wrapper -->
<div th:replace="script"></div>

<script th:src="@{/js/jquery.serializejson.min.js}"></script>
<script th:src="@{/js/ajax-setup.js}"></script>
<script th:src="@{/js/form-json-submit.js}"></script>
<script th:inline="javascript">
    function backToList() {
        location.href = [[@{/blogsite/book/{bookId}/indexs(bookId =${bookId});
    }]]
    };

    $(function () {
        $("#submitBtn").click(function (event) {
               var url=$("#url").val();
                if (!(url.startsWith("/") || url.startsWith("http://") || url.startsWith("https://"))){
                    url="/book/[(${bookId})]/blog/"+url;
                    $("#url").val(url);
                }
        });
    })


</script>
</body>
</html>